Picker: support custom default date via setDefaultDate (#4973)#4974
Merged
Conversation
Adds Picker.DateGetter plus setDefaultDate(DateGetter)/setDefaultDate(Date) so PICKER_TYPE_DATE, PICKER_TYPE_DATE_AND_TIME, and PICKER_TYPE_CALENDAR pickers can show a caller-supplied initial value (resolved lazily on each open) instead of always defaulting to `new Date()`. After a successful selection the picked value pins the picker and the getter is no longer consulted; clearing with setDate(null) (or switching off a date type) re-enables it. Custom lightweight popup buttons that call setDate during edit are snapshotted/rolled back on Cancel so default-getter behavior survives a cancelled action. getDate() returns the resolved default when no explicit value has been set so the UI and programmatic read agree. Behavior with no setDefaultDate call is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Compared 107 screenshots: 107 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
Collaborator
Author
|
Compared 107 screenshots: 107 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 107 screenshots: 107 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
SpotBugs (SIC_INNER_SHOULD_BE_STATIC_ANON) flagged the anonymous DateGetter created by setDefaultDate(Date) - it captures no Picker state, so promoting it to a named static inner class avoids the hidden enclosing-Picker reference and clears the CI gate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
Covers: fixed default, dynamic getter re-evaluation, explicit setDate override, setDate(null) re-enables default, clearing the getter, getDefaultDate accessor, setType-off-and-back reset, DATE_AND_TIME support, null-returning getter falls back to new Date(), and the custom-popup-button cancel rollback path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Picker.DateGetterplussetDefaultDate(DateGetter)/setDefaultDate(Date)so date-type pickers (PICKER_TYPE_DATE,PICKER_TYPE_DATE_AND_TIME,PICKER_TYPE_CALENDAR) can show a caller-supplied initial value instead of always defaulting tonew Date().getDate()is called against an unset picker), so dependent defaults like "reminder = due date - 1 hour" stay in sync with the value they depend on.setDate(null)(or switching off a date type) re-enables it. Cancel paths — including a Cancel after a custom lightweight-popup button that internally calledsetDate(...)— roll back to the pre-edit explicit-flag, so the default getter keeps working on the next open.Implements #4973.
Test plan
mvn -pl core -am compilesucceeds (verified locally).Picker.setType(PICKER_TYPE_DATE)+setDefaultDate(() -> dueDate.minusHours(1))shows the resolved default when opened without a priorsetDate.setDate(null)re-enables the dynamic default on the next open.setDefaultDatecall behave exactly as before.🤖 Generated with Claude Code